﻿@model Matrix.MaKaYunShang.Model.CardCategory
@{
    ViewBag.Title = "编辑卡券类别";
    ViewBag.PathToBtn = "/CardCategory/List";
    ViewBag.TextBtn = "返回至列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                卡券类别信息
            </div>
            <div class="panel-body">
                <div class="row">
                    @using (Html.BeginForm("Update", "CardCategory", FormMethod.Post, new { id = "frmUpdate", enctype = "multipart/form-data" }))
                    {
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)

                        <div class="col-lg-12">
                            <fieldset>
                                @Html.HiddenFor(model => model.Id)
                                <div class="form-group col-md-6">
                                    <label>类别名称</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.CategoryName, new { @class = "form-control", placeholder = "卡卷名称" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>类别编码</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.CategoryCode, new { @class = "form-control", disabled = "disabled" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>描述</label>
                                    <div class="input-group">
                                        @Html.TextAreaFor(model => model.Description, new { @class = "form-control", rows = "5", cols="200", placeholder = "描述", maxlength = 200 })
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>警示信息</label>
                                    <div class="input-group">
                                        @Html.TextAreaFor(model => model.WarningInfo, new { @class = "form-control", rows = "5", cols = "200", placeholder = "警示信息", maxlength = 200 })
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <button id="btnSave" type="button" class="btn btn-primary">保存</button>
                                    <button id="btnReset" type="reset" class="btn btn-outline btn-primary">清空设置</button>
                                </div>
                            </fieldset>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
</div>
@section javascript{
    <script type="text/javascript">
        $(function () {
            $("#frmUpdate").validate({
                rules: {
                    CategoryName: { required: true }
                },
                messages: {
                    CategoryName: { required: "请填写类别名称" }
                }
            });

            $("#btnSave").click(function () {
                if ($("#frmUpdate").valid()) {
                    $.ajax({
                        type: 'post',
                        url: '@Url.Action("Update")',
                        data: $("#frmUpdate").serialize(),
                        success: function (data) {
                            if (data.Status) {
                                alertify.success("保存成功");
                                setTimeout(function () {
                                    window.location.href = "/CardCategory/List";
                                }, 500);
                            } else {
                                alertify.error(data.Message);
                            }
                        },
                        error: function () {
                            alertify.error("保存失败，请重试！");
                        }
                    });
                }
            });
        });

    </script>
}